package com.ruoyi.project.wodemand.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.project.hr.domain.THrContractinfo;
import com.ruoyi.project.wodemand.domain.SelectVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wodemand.domain.TLogicCode;
import com.ruoyi.project.wodemand.service.ITLogicCodeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 逻辑运算码Controller
 *
 * @author lt
 * @date 2020-04-21
 */
@RestController
@RequestMapping("/wodemand/CODE")
public class TLogicCodeController extends BaseController
{
    @Autowired
    private ITLogicCodeService tLogicCodeService;

    /**
     * 查询逻辑运算码列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TLogicCode tLogicCode)
    {
        startPage();
        List<TLogicCode> list = tLogicCodeService.selectTLogicCodeList(tLogicCode);
        return getDataTable(list);
    }

    /**
     * 查询逻辑运算码列表
     */
    @GetMapping("/listCode")
    public AjaxResult listCode(TLogicCode tLogicCode)
    {
        List<TLogicCode> list = tLogicCodeService.selectTLogicCodeList(tLogicCode);
        List<SelectVo> list1 = new ArrayList<>();
        for (int i = 0; i <list.size() ; i++) {
            SelectVo selectVo = new SelectVo();
            selectVo.setLabel(list.get(i).getLogicSymbolName());
            selectVo.setValue(list.get(i).getLogicCode());
            list1.add(selectVo);
        }
        AjaxResult aTrue = new AjaxResult(200, "true", list1);
        return aTrue;
    }

    /**
     * 导出逻辑运算码列表
     */
    @PreAuthorize("@ss.hasPermi('wodemand:CODE:export')")
    @Log(title = "逻辑运算码", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TLogicCode tLogicCode)
    {
        List<TLogicCode> list = tLogicCodeService.selectTLogicCodeList(tLogicCode);
        ExcelUtil<TLogicCode> util = new ExcelUtil<TLogicCode>(TLogicCode.class);
        return util.exportExcel(list, "CODE");
    }

    /**
     * 获取逻辑运算码详细信息
     */
    @PreAuthorize("@ss.hasPermi('wodemand:CODE:query')")
    @GetMapping(value = "/{logicCode}")
    public AjaxResult getInfo(@PathVariable("logicCode") String logicCode)
    {
        return AjaxResult.success(tLogicCodeService.selectTLogicCodeById(logicCode));
    }

    /**
     * 新增逻辑运算码
     */
    @PreAuthorize("@ss.hasPermi('wodemand:CODE:add')")
    @Log(title = "逻辑运算码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TLogicCode tLogicCode)
    {
        return toAjax(tLogicCodeService.insertTLogicCode(tLogicCode));
    }

    /**
     * 修改逻辑运算码
     */
    @PreAuthorize("@ss.hasPermi('wodemand:CODE:edit')")
    @Log(title = "逻辑运算码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TLogicCode tLogicCode)
    {
        return toAjax(tLogicCodeService.updateTLogicCode(tLogicCode));
    }

    /**
     * 删除逻辑运算码
     */
    @PreAuthorize("@ss.hasPermi('wodemand:CODE:remove')")
    @Log(title = "逻辑运算码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logicCodes}")
    public AjaxResult remove(@PathVariable String[] logicCodes)
    {
        return toAjax(tLogicCodeService.deleteTLogicCodeByIds(logicCodes));
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<TLogicCode> util = new ExcelUtil<TLogicCode>(TLogicCode.class);
        return util.importTemplateExcel("判断依据导入模板");
    }
}
